package info.wf0913.blogger_service.controller;

import info.wf0913.blogger_core.bean.Result;
import info.wf0913.blogger_core.controller.BaseController;
import info.wf0913.blogger_service.bean.Essay;
import info.wf0913.blogger_service.service.EssayService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/essay")
public class EssayController extends BaseController<EssayService, Essay> {

    /**
     * 查询详细信息
     * @param
     * @return
     */
    @GetMapping("/selectOne/{id}")
    public Result selectList(@PathVariable("id") Integer id){
        try {
            Essay essay=service.selectOne(id);
            return Result.ok().setData(essay);
        }catch (Exception e){
            System.out.println(e);
            return Result.failure();
        }


    }
    /**
     * 搜索查询
     */
    @GetMapping("/getQuery")
    public Result  getQuery(String head){
        try {
            List<Essay> essays = service.selectList(head);
            System.out.println("================");
            essays.forEach(System.out::println);
            return Result.ok().setData(essays);

        }catch (Exception e){
            System.out.println(e);
            return Result.failure();
        }
    }
}
